<?php


namespace App\Model;

use EasySwoole\ORM\AbstractModel;

/**
 * Class UserModel
 * @property $id
 * @property $avatar
 * @property $username
 * @property $nickname
 * @property $mobile
 * @property $userLevelId
 * @property $pasword
 * @property $status
 * @property $createTime
 * @property $updateTime
 * @property $deleteTime
 */
class UserModel extends AbstractModel
{
    protected $tableName = 'user';

    protected $primaryKey = 'id';

    /**
     * @getAll
     * @keyword adminName
     * @param  int  page  1
     * @param  string  keyword
     * @param  int  pageSize  10
     * @return array[total,list]
     */
    public function getAll(int $page = 1, string $keyword = null, int $pageSize = 10): array
    {
        $where = [];
        if (!empty($keyword)) {
            $where['username'] = ['%' . $keyword . '%', 'like'];
        }
        $list = $this->limit($pageSize * ($page - 1), $pageSize)
            ->order($this->primaryKey, 'DESC')
            ->withTotalCount()
            ->all($where);
        $total = $this->lastQueryResult()->getTotalCount();
        return ['total' => $total, 'list' => $list];
    }

}
